package com.ruoyi.system.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.ByParamMapper;
import com.ruoyi.system.mapper.DateUtilSqlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.MxWareMapper;
import com.ruoyi.system.domain.MxWare;
import com.ruoyi.system.service.IMxWareService;

/**
 * 仓库管理Service业务层处理
 *
 * @author yushuaixm
 * @date 2024-08-15
 */
@Service
public class MxWareServiceImpl implements IMxWareService {
    @Autowired
    private MxWareMapper mxWareMapper;

    @Autowired
    private DateUtilSqlMapper dateUtilSqlMapper;

    @Autowired
    private ByParamMapper paramMapper;

    @Override
    public List<JSONObject> getDataByProductId(String pro_id) {
        return mxWareMapper.getDataByProductId(pro_id);
    }

    /**
     * 查询仓库管理
     *
     * @param id 仓库管理主键
     * @return 仓库管理
     */
    @Override
    public MxWare selectMxWareById(Long id) {
        return mxWareMapper.selectMxWareById(id);
    }

    /**
     * 查询仓库管理列表
     *
     * @param mxWare 仓库管理
     * @return 仓库管理
     */
    @Override
    public List<MxWare> selectMxWareList(MxWare mxWare) {
        return mxWareMapper.selectMxWareList(mxWare);
    }

    /**
     * 新增仓库管理
     *
     * @param mxWare 仓库管理
     * @return 结果
     */
    @Override
    public int insertMxWare(MxWare mxWare) {
        mxWare.setAddtime(dateUtilSqlMapper.getNowDateTime());
        mxWare.setUpTime(dateUtilSqlMapper.getNowDateTime());
        if (!StringUtils.isEmpty(mxWare.getGg() + "")) {
            JSONObject json = paramMapper.getParamJSONObjectById(mxWare.getGg() + "");
            mxWare.setGgName(json.getString("val"));
        }
        return mxWareMapper.insertMxWare(mxWare);
    }

    /**
     * 修改仓库管理
     *
     * @param mxWare 仓库管理
     * @return 结果
     */
    @Override
    public int updateMxWare(MxWare mxWare) {
        mxWare.setUpTime(dateUtilSqlMapper.getNowDateTime());
        if (!StringUtils.isEmpty(mxWare.getGg() + "")) {
            JSONObject json = paramMapper.getParamJSONObjectById(mxWare.getGg() + "");
            mxWare.setGgName(json.getString("val"));
        }
        return mxWareMapper.updateMxWare(mxWare);
    }

    /**
     * 批量删除仓库管理
     *
     * @param ids 需要删除的仓库管理主键
     * @return 结果
     */
    @Override
    public int deleteMxWareByIds(Long[] ids) {
        return mxWareMapper.deleteMxWareByIds(ids);
    }

    /**
     * 删除仓库管理信息
     *
     * @param id 仓库管理主键
     * @return 结果
     */
    @Override
    public int deleteMxWareById(Long id) {
        return mxWareMapper.deleteMxWareById(id);
    }
}
